package com.zhang.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhang.pojo.ProductBean;
import com.zhang.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "库存控制层接口")
@RestController
@RequestMapping("product")
public class ProductController {
    @Autowired
    private IProductService productService;

    @ApiOperation("根据商品名，类别，起始数量，结束数量动态查询并分页")
    @GetMapping("findByItemAndPage")
    public IPage<ProductBean> findByPageAndItem(Integer current,
                                                Integer pageSize,
                                                String productName,
                                                Integer typeId,
                                                Integer startNum,
                                                Integer endNum){
       return productService.findByItemAndPage(new Page<>(current,pageSize),productName,typeId,startNum,endNum);
    }

    @ApiOperation("根据商品id查询商品")
    @GetMapping("findById")
    public ProductBean findById(int id){
       return  productService.findById(id);
    }

    @ApiOperation("根据商品id修改销售价")
    @PutMapping("update")
    public String  update(int id,int money){
        try {
            productService.updateMoney(id, money);
            return "ok";
        } catch (Exception e) {
            return "no";
        }
    }
}
